﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PloobsEngine.Material;
using PloobsEngine;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using PloobsEngine.Modelo;

namespace Etapa1.BezierExperiments
{
    public class CurveShader : IShader
    {
        public override MaterialType MaterialType
        {
            get { return MaterialType.DEFERRED; }
        }

        Effect _shader;
        public override void Initialize()
        {
            _shader = EngineStuff.CustomContentManager.GetAsset<Effect>("Effects/curves");
            base.Initialize();
        }

        public override void Draw(IModelo modelo, PloobsEngine.SceneControl.IRenderHelper render, PloobsEngine.Cameras.ICamera cam)
        {
            PosDrawPhase(modelo, render, cam, lights);
        }

        public override void  PosDrawPhase(IModelo modelo, PloobsEngine.SceneControl.IRenderHelper render, PloobsEngine.Cameras.ICamera cam, IList<PloobsEngine.Light.ILight> lights)
        {

            VertexBufferModel vbm = modelo as VertexBufferModel;

            _shader.Parameters["World"].SetValue(Matrix.Identity);
            _shader.Parameters["View"].SetValue(cam.View);
            _shader.Parameters["Projection"].SetValue(cam.Projection);
            BatchInformation bi = vbm.GetBatchInformation(0)[0];

            this._shader.Begin();
            EngineStuff.GraphicsDevice.VertexDeclaration = bi.VertexDeclaration;
            EngineStuff.GraphicsDevice.Vertices[0].SetSource(vbm.GetVertexBuffer(0), 0, bi.VertexDeclaration.GetVertexStrideSize(0));

            this._shader.CurrentTechnique.Passes[0].Begin();
            EngineStuff.GraphicsDevice.DrawPrimitives(PrimitiveType.LineStrip, 0, bi.PrimitiveCount);
            this._shader.CurrentTechnique.Passes[0].End();
            this._shader.End();
            

        }
    }
}
